<?php 
class Model_Testimonial extends Database
{
	
	function Model_Testimonial()
	{
		$this->testimonial = TESTIMONIAL;	
		$this->users       = USERS;
		$this->Database();
	}
	

	// Delete Welcome Menu
	function deleteTestimonialById($id)
	{
		$this->DeleteData($this->testimonial,"id",$id);
	}
		
	//updating status of multiple testimonials
    function updateTestimonialStatus($testiArray ,$status){
		$sql = "UPDATE ".$this->testimonial." SET status = '".$status."' WHERE id IN (".$testiArray.")";
		$result1= $this->ExecuteQuery($sql);	 	
 
	}
	
	//deleting multiple testimonials
	function deletemultiTestimonials($ids)
	{
		$sql = "delete FROM ".$this->testimonial." WHERE id in (".$ids.")";
		$result1= $this->ExecuteQuery($sql);
	}	
    // Update Welcome Menu
	function edit_Testimonial( $array , $id )
	{
		$this->UpdateData( $this->testimonial , $array , "id" , $id, 0);		
	}
    
    	// Getting All Welcome Menu
	function list_Testimonial($val,$col1='',$col2='', $limit, $offset, $is_page) {
		
		if($val != ''){
			$where = "concat(user.first_name,' ',user.last_name) LIKE '%".$val."%'" ;
		}else{
			$where = "1";			
		}
		if($col1 =='0')
		{
			$order = "user.first_name ASC";
		}
		if($col2 =='0')
		{
			$order = "test.added_date ASC";
		}
	
		if($col1 =='1')
		{
			$order = "user.first_name DESC";
		}
		if($col2 =='1')
		{
			$order = "test.added_date DESC";
		}
	
		
		$sql = "SELECT test.*,user.first_name as firstname, user.last_name as lastname FROM ".$this->testimonial." as test LEFT JOIN ".$this->users." as user ON user.id= test.user_id WHERE ".$where." ORDER BY $order";
		
	//	$sql = "SELECT * FROM ".$this->testimonial." WHERE ".$where." ORDER BY added_date DESC";
		// Paggination condition
		if($is_page == true)
			 $sql.=" LIMIT ".$offset.",".$limit;
		$result1= $this->ExecuteQuery($sql);
		$result= $this->FetchAll($result1);
		return $result;
    }
	
	function list_TestimonialDetailsById($id) {
		$fields     = array();
		$tableName  = array($this->testimonial);
		$whereCondn = array('id = '.$id);
		$result     = $this->SelectData($fields,$tableName, $whereCondn, $order = array(), $group=array(),$limit = "",0,0);
		$details    = $this->FetchRow($result);
		return $details;
    }

	function list_TestimonialFrontwithlimit($limit, $offset,$is_page)
	{
		$sql = "SELECT test.*,user.first_name as firstname, user.last_name as lastname FROM ".$this->testimonial." as test LEFT JOIN ".$this->users." as user ON user.id= test.user_id where test.status = '1'  ORDER BY added_date DESC ";
		// Paggination condition
		if($is_page == true)
			$sql.=" LIMIT ".$offset.",".$limit;
		$result1 = $this->ExecuteQuery($sql);
		$result = $this->FetchAll($result1);
		return $result;
	}
    // function for getting Welcome Meny By Id
	function Get_testimonial($id)
	{
		$fields=array();
		$tables=array($this->testimonial);
		$where=array("id='".$id."'");
		$result1 = $this->SelectData($fields,$tables, $where, $order = array(), $group=array(),$limit = "",0,0);
		$result= $this->FetchRow($result1);
		return $result;		
	}
	
	function Get_TestimonialFrontById($id) {
				
		$sql = "SELECT test.*,user.first_name as firstname, user.last_name as lastname FROM ".$this->testimonial." as test LEFT JOIN ".$this->users." as user ON user.id= test.user_id WHERE test.id = ".$id."  ORDER BY added_date DESC";
		$result1= $this->ExecuteQuery($sql);
		$result= $this->FetchAll($result1);
		return $result;
    }
    
	
    // Insert Welcome Menu
	function add_Testimonial( $array )
	{
		$this->InsertData( $this->testimonial , $array );		
		$insertId = mysql_insert_id();
		return $insertId;
	}
    
    function Get_Welcome_menu_forhome()
	{
		$fields=array();
		$tables=array($this->testimonial);
		$where=array("");
		$result1 = $this->SelectData($fields,$tables, $where, $order = array(), $group=array(),$limit = "",0,0);
		$result= $this->FetchRow($result1);
		return $result;		
	}
	
	
	###### Deleting testimonials by user Ids 
	function deletingMultipleTestimonialsByUserIds($ids){
		$sql = "DELETE FROM ".$this->testimonial." WHERE user_id IN (".$ids.")";
		$this->ExecuteQuery($sql);
	}
	
	#### Function deleting testimonial By Singel User Id 
	
	function deleteTestimonialsByUserId($user_id){
		$this->DeleteData($this->testimonial,"user_id",$user_id,0);
	}
  
  
  ## Get testimonilas according to the user Id 
  function testimonialsAccordingToUserId($userId,$limit =0,$offset = 0,$isPage){
		$fields  = array();
		$tables  = array($this->testimonial);
		 if($isPage == true){
			$limit  = $limit;
			$offset = $offset;
		 }
		$where   = array("user_id =".$userId);
		$result1 = $this->SelectData($fields,$tables, $where, $order = array("id DESC"), $group=array(),$limit,$offset,0);
		$result  = $this->FetchAll($result1);
		return $result;		
  }

  ## Get last testimonial details  
  function LastTestimonialDetails() {
		$fields     = array();
		$tableName  = array($this->testimonial);
		$whereCondn = array("status = '1'");
		$result     = $this->SelectData($fields,$tableName, $whereCondn, $order = array("id DESC"), $group=array(),$limit = "1",0,0);
		$details    = $this->FetchRow($result);
		return $details;
	}	

 ## Get all testimonial 
  function getAllTestimonialDetails() {
		$fields     = array();
		$tableName  = array($this->testimonial);
		$whereCondn = array("status = '1'");
		$result     = $this->SelectData($fields,$tableName, $whereCondn, $order = array("id DESC"), $group=array(),$limit = "",0,0);
		$details    = $this->FetchAll($result);
		return $details;
	}		
}
?>